<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表渲染-Vue监测数据改变的原理-数组监测</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>

    <div id="root">
        <h1>学校信息</h1>
        <h2>学校名称：{{name}}</h2>
        <h2>学校地址：{{address}}</h2>
        <hr>
        <h1>学生信息</h1>
        <button @click="addSex">点我增加一个性别属性</button>
        <h2 v-if="student.sex">性别：{{student.sex}}</h2>
        <h2>学生姓名：{{student.name}}</h2>
        <h2>学生真实年龄：{{student.age.trueAge}}</h2>
        <h2>学生虚假年龄：{{student.age.falseAge}}</h2>
        <h2>朋友们</h2>
        <ul>
            <li v-for="(f,index) in student.friends" ::key="index">
                {{f.name}}--{{f.age}}
            </li>
        </ul>
        <h2>爱好</h2>
        <ul>
            <li v-for="(h,index) in student.hobby" ::key="index">
                {{h}}
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript">

    const vm = new Vue({
        el: '#root',
        data: {
            name: '北京大学',
            address: '北京',
            student: {
                name: '张三',
                age: {
                    trueAge: 18,
                    falseAge: 20
                },
                hobby:[
                    '抽烟','喝酒','烫头'
                ],
                friends: [
                    { name: '李四', age: 18 },
                    { name: '小七', age: 15 },
                ]
            }
        },
        methods: {
            addSex(){
                // Vue.set(this.student,'sex','男')
                this.$set(this.student,'sex','男')
            }
        },
    })
</script>

</html>